<?php
namespace Admin\Controller;

/**
 * 战队
 */
class GameTeamController extends BaseManageController {
    /**
    *控制操作的模型表
    */
    protected $modelName = 'Common/GameTeam';

    /**
    *删除类型的设置 true|直接删除， false|设置数据状态
    */  
    protected $is_del   = false;

    /**
    *跳转的Url
    */
    protected $jumpAct  = 'GameTeam/index';

    /**
    *操作index的前置操作
    *---设置数据筛选条件---
    */
    public function _before_index()
    {
        $map = array();//筛选条件
        $map['status'] = array('egt',0);

        $this->name = $name = trim(I('get.name', '', 'strip_tags'));
        if($name){
            $map['name']    =   array('like', (string)$name);
        }

        $this->game = $game = I('get.game', 0, 'intval');
        if($game){
            $map['game_id'] = $game;
        }
        $this->where = $map;

        $this->gameInfo(true);
    }

    /**
    *add的前置操作
    */
    public function _before_add()
    {
        $this->gameInfo();
    }

    /**
    *edit的前置操作
    */
    public function _before_edit()
    {
        $this->gameInfo();
    }

    /**
    *游戏信息获取
    */
    private function gameInfo($format=false){

        $games = A('Api/Game', 'Event')->lists(array(), 'id,name');

        if($format===false){

            $this->games = $games;

        }else{

            $temp = array();
            foreach ($games as $key => $value) {
                $temp[$value['id']] = $value['name'];
            }

            $this->games = $temp;
        }
    }
}